home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2778 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Floating point calculation order
  5. Date: 23 Jan 1996 21:46:37 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Jan23144637@qcd.lanl.gov>
  8. References: <m0tedv8-0002eqC@sice.nsk.su> <3104c6d9.134061184@nntp.ix.netcom.com>
  9.     <DLnE5K.2xH@microunity.com>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: toms@MicroUnity.com's message of Tue, 23 Jan 1996 19:00:56 GMT
  14.  
  15. --text follows this line--
  16. In article <DLnE5K.2xH@microunity.com> toms@MicroUnity.com (Tom
  17. Sanders) writes: 
  18. <snip>
  19.    |> >  Having declaration
  20.    |> > 
  21.    |> >  double x, p, q, r;
  22.    |> > 
  23.    |> > my compiler (cc on SCO 3.2) calculated following expression:
  24.    |> > 
  25.    |> >  x = p * q / r;
  26.    |> > 
  27.    |> > as p * (q/r); (I mean, it divided first, than multiplied). That 
  28.    |> > resulted in precision loss.
  29.    |> > 
  30.    |> > Is this legal behavior?
  31.    |> 
  32.    |> Not in ANSI C, but it was legal in K&R. If memory serves, it was not
  33.    |> made illegal until very late in the standardizattion process so if
  34.    |> your compiler was written before the standard was finalized it may not
  35.    |> adhere to this.
  36.    |> 
  37.    |> Michael M Rubenstein
  38.  
  39.    I am a firm believer in not allowing a compiler to make these decisions for
  40.    me.  It's best to specify with parens the order of evaluation and not leave
  41.    it up to the compiler defaults.  I would actually prefer a compiler that
  42.  
  43. I agree that redundant parens are often useful for clarity, but I take
  44. issue at calling language semantics as `compiler defaults'. When I
  45. write in C, I expect everyone reading it to know C, and the compiler
  46. to compile according to C rules.
  47.  
  48. I write `a = b + c' instead of `a = (b + c)' regularly, and I would
  49. refuse to buy a compiler which thought `(a = b) + c' was an alternate
  50. meaning I might have been thinking of, and warn me about such
  51. possibilities. 
  52.  
  53. There is absolutely no ambiguity in `p * q / r', and no parentheses
  54. are necessary.
  55.  
  56.    gave a warning if I did have an equation that could be evaluated in more
  57.    than 1 order (something I have not done in over 20 years).
  58.  
  59. I am almost certain you write `a + b * c' contrary to your claim. Do
  60. you mean `a + (b * c)' or `(a + b) * c' when, if, you do it? If you do
  61. not, you are in a very small minority.
  62.  
  63. Cheers
  64. Tanmoy
  65. --
  66. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  67. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  68. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  69. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  70. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  71. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  72.